
#include "display.h"

Display::Display() : Widget()
{
    QLinearGradient gradient(QPointF(50, -20), QPointF(80, 20));
    gradient.setColorAt(0.0, Qt::white);
    gradient.setColorAt(1.0, QColor(0xa6, 0xce, 0x39));

    background = QBrush(Qt::black);
    circleBrush = QBrush(gradient);
    circlePen = QPen(Qt::black);
    circlePen.setWidth(1);
    //textPen = QPen(Qt::white);
    //textFont.setPixelSize(50);
}

Display::~Display()
{
}

void Display::paintEvent(QPaintEvent *event)
{
    QPainter painter;
    painter.begin(this);
    painter.setRenderHint(QPainter::Antialiasing);
    paint(&painter, event, elapsed % 1000);
    painter.end();
}

void Display::paint(QPainter *painter, QPaintEvent *event, int elapsed)
{
    int wd = this->width();
    int ht = this->height();
    painter->fillRect(event->rect(), background);
    painter->translate(wd>>1,ht>>1);

    painter->save();
    painter->setBrush(circleBrush);
    painter->setPen(circlePen);
    painter->rotate(elapsed * 0.360);

    qreal r = elapsed / 1000.0;
    int n = 72;
    for (int i = n-1; i > -1; i--) {
        painter->rotate(10);
        qreal factor = (i + r) / n;
        qreal radius = 0 + 120.0 * factor;
        qreal circleRadius = 1 + factor * 20;
        painter->drawEllipse(
            QRectF(radius, -circleRadius, circleRadius * 2, circleRadius * 2));
    }
    painter->restore();

    //painter->setPen(textPen);
    //painter->setFont(textFont);
    //painter->drawText(QRect(-50, -50, 100, 100), Qt::AlignCenter, QStringLiteral("Qt"));
}
